<?php    
    $hashid = arrGet($_POST,"hashid");
    
    # Hae data
    $tp = API::trainingProgramLoad(array(
        "hashid" => $hashid
    ));
?>

<div class="panel panel-default">
    <div class="panel-body">        
        <div class="row">    
            <div class="col-sm-3">
                <strong>Start date</strong>
            </div>
            <div class="col-sm-9">
                <?php
                    echo htmlescape(arrGet($tp,"startdate"));
                ?>
            </div>
        </div>
        
        <div class="row">            
            <div class="col-sm-3">
                <strong>End date</strong>
            </div>
            <div class="col-sm-9">
                <?php
                    echo htmlescape(arrGet($tp,"enddate"));
                ?>
            </div>
        </div>
        
        <div class="row">            
            <div class="col-sm-3">
                <strong>Workouts</strong>
            </div>
            <div class="col-sm-9">
                <?php
                    echo htmlescape(arrGet($tp,"workout_count"),array());
                ?>
            </div>
        </div>
        
        <div class="row">
            <div class="col-sm-3">
                <strong>&nbsp;</strong>
            </div>
            <div class="col-sm-9">
                <a class="a-navigation"
                  data-ui-view="edittrainingprogram"
                  data-hashid="<?php echo htmlescape($hashid); ?>"
                  href="#">
                    Edit training program
                </a>
            </div>
        </div>
        
        <div class="row">
            <div class="col-sm-3">
                <strong>&nbsp;</strong>
            </div>
            <div class="col-sm-9">
                <a class="a-navigation"
                  data-ui-view="addtrainingprogram"
                  data-hashid="<?php echo htmlescape($hashid); ?>"
                  data-copy="1"
                  href="#">
                    Copy training program
                </a>
            </div>
        </div>
    </div>
</div>

<?php
    $records = (array)arrGet($tp,"records");
    if (count($records) > 0) {
    ?>
        <div class="panel panel-default">
            <div class="panel-body">
                <strong>Notes</strong>
                <p>
                    <?php
                        $record = arrGet($records[0],"record");
                        $record = htmlescape(trim($record));
                        echo nl2br($record);
                    ?>
                </p>
            </div>
        </div>
    <?php
    }
?>

<table class="table table-striped">
    <thead>
        <tr>
            <th>
                Template
            </th>
            <th>
                Days to next workout
            </th>            
        </tr>
    </thead>
    
    <tbody>
        <?php
            $links = (array)arrGet($tp,"templatelink");
            foreach ($links as $link) {
            ?>
                <tr>
                    <td>
                        <a class="a-subview-dialog"
                          data-ui-view="templatelist"
                          data-ui-subview="info"
                          data-ui-title="<?php echo htmlescape($link["template_extratext"]); ?>"
                          data-hashid="<?php echo htmlescape($link["templatehashid"]); ?>"
                          data-training-program-hashid="<?php echo htmlescape($hashid); ?>"
                          href="#">
                            <?php echo htmlescape($link["template_extratext"]); ?>
                        </a>    
                    </td>
                    <td>
                        <?php echo htmlescape($link["days_to_next_workout"]); ?>
                    </td>
                </tr>
            <?php
            }
        ?>
    </tbody>
</table>